package com.yunxin.core.infra.persistence.repository.channel;

import com.yunxin.core.domain.model.channel.ChannelPromotionLinkConfig;
import com.yunxin.core.domain.model.channel.ChannelPromotionLinkConfigRepository;
import com.yunxin.core.infra.persistence.converter.ChannelConvertor;
import com.yunxin.core.infra.persistence.entity.channel.ChannelPromotionLinkConfigDO;
import com.yunxin.core.infra.persistence.mapper.channel.ChannelPromotionLinkConfigExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author zero°
 * @since 2023-07-12
 */
@Repository
@RequiredArgsConstructor
public class ChannelPromotionLinkConfigRepositoryImpl implements ChannelPromotionLinkConfigRepository {

    private final ChannelPromotionLinkConfigExtendMapper channelPromotionLinkConfigExtendMapper;

    private final ChannelConvertor channelConvertor;
    @Override
    public boolean saveChannelPromotionLinkConfig(ChannelPromotionLinkConfig channelPromotionLinkConfig) {
        ChannelPromotionLinkConfigDO channelPromotionLinkConfigDO = channelConvertor.formChannelPromotionLinkConfig(channelPromotionLinkConfig);
        int result = channelPromotionLinkConfigExtendMapper.insertSelective(channelPromotionLinkConfigDO);
        return result > 0;
    }

    @Override
    public boolean updateChannelPromotionLinkConfig(ChannelPromotionLinkConfig channelPromotionLinkConfig) {
        ChannelPromotionLinkConfigDO channelPromotionLinkConfigDO = channelConvertor.formChannelPromotionLinkConfig(channelPromotionLinkConfig);
        int result = channelPromotionLinkConfigExtendMapper.updateByPrimaryKeySelective(channelPromotionLinkConfigDO);
        return result > 0;
    }

    @Override
    public ChannelPromotionLinkConfig getByPromotionId(Long promotionId) {
        ChannelPromotionLinkConfigDO channelPromotionLinkConfigDO = channelPromotionLinkConfigExtendMapper.selectByPromotionId(promotionId);
        return channelConvertor.toChannelPromotionLinkConfig(channelPromotionLinkConfigDO);
    }
}
